﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Tiens.NotificationHub.Services;

namespace Tiens.NotificationHub.WebHost.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class AppController : ControllerBase
    {
        private readonly IAppConnectionManager _connectionManager;


        public AppController(IAppConnectionManager connectionManager)
        {
            _connectionManager = connectionManager;
        }

        [HttpGet("{appId}/user/online")]
        public async Task<ActionResult<IEnumerable<string>>> UsersOnline([FromRoute] string appId)
        {
            if (string.IsNullOrWhiteSpace(appId))
                return NotFound();

            var users = await _connectionManager.UsersOnline(appId);
            return Ok(users);
        }

        [HttpGet("{appId}/user/online/count")]
        public async Task<ActionResult<int>> UsersOnlineCount([FromRoute] string appId)
        {
            if (string.IsNullOrWhiteSpace(appId))
                return NotFound();

            var num = await _connectionManager.UsersOnlineNumber(appId);
            return Ok(num);
        }
    }
}
